package main

import (
	"Bluebell/common/snowflake"
	"Bluebell/common/util"
	"Bluebell/dao/mysql"
	"Bluebell/dao/redis"
	"Bluebell/logger"
	"Bluebell/routers"
	"Bluebell/settings"
	"fmt"
	"go.uber.org/zap"
)

// @title Blubell项目接口文档
// @version 1.0.0
// @description goweb项目文档
// @termsOfService http://swagger.io/terms/

// @contact.name GrandeLai
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host 8080
// @BasePath 127.0.0.1:8080/
func main() {
	// 1. 加载配置
	if err := settings.Init(); err != nil {
		fmt.Printf("init settings failed, err:%v\n", err)
		return
	}
	fmt.Println(settings.Conf.StartTime)
	// 2. 初始化日志
	if err := logger.Init(settings.Conf.LogConfig, settings.Conf.Mode); err != nil {
		fmt.Printf("init logger failed, err:%v\n", err)
		return
	}
	defer zap.L().Sync()
	zap.L().Debug("logger init success...")
	// 3. 初始化MySQL连接
	if err := mysql.InitMySQL(settings.Conf.MySQLConfig); err != nil {
		panic(err)
	}
	defer mysql.Close()

	//4. 初始化Redis连接
	if err := redis.Init(settings.Conf.RedisConfig); err != nil {
		fmt.Printf("init redis failed, err:%v\n", err)
		return
	}
	defer redis.Close()
	//雪花算法初始化
	if err := snowflake.Init(1); err != nil {
		fmt.Printf("init snowflake failed, err:%v\n", err)
		return
	}

	//初始化翻译器
	if err := util.InitTrans("zh"); err != nil {
		fmt.Printf("init trans failed,err:%v\n", err)
		return
	}
	// 5. 注册路由
	r := routers.Setup(settings.Conf.Mode)
	err := r.Run(":8080")
	if err != nil {
		fmt.Printf("run server failed, err:%v\n", err)
		return
	}
}
